﻿using System;
using System.Drawing;
using System.Collections.Generic;
using System.Diagnostics;

namespace iPhoneUI.Widgets
{
    public class ImageWidget : Widget
    {
        private Image m_image;
        private Rectangle m_imageRectangle;

        public ImageWidget()
        {
        }

        public Image Image
        {
            get
            {
                return m_image;
            }
            set
            {
                m_image.SafeDispose();
                Debug.Assert(value != null);
                m_image = value;
                m_imageRectangle = Rectangle.FromLTRB(0, 0, m_image.Width, m_image.Height);

                if (SnapStyle == SnapStyle.None)
                    Size = m_image.Size;
            }
        }

        protected override void OnDraw(Canvas canvas, Rectangle clipBounds)
        {
            canvas.DrawImage(m_image, ClientArea, m_imageRectangle);
        }

        protected override void OnDispose()
        {
            m_image.SafeDispose();
            base.OnDispose();
        }
    }
}
